package com.whitedust.top40;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author A
 * @since 2025/11/5 10:36
 */

public class Top40 {
    public int compareVersion(String version1, String version2) {
        String[] split1 = version1.split("\\.");
        String[] split2 = version2.split("\\.");
        List<String> nums1 = Arrays.stream(split1).collect(Collectors.toList());
        List<String> nums2 = Arrays.stream(split2).collect(Collectors.toList());
        int len1 = split1.length;
        int len2 = split2.length;
        if (len1 > len2) {
            for (int i = 0; i < len1 - len2; i++) {
                nums2.add("0");
            }
        } else {
            for (int i = 0; i < len2 - len1; i++) {
                nums1.add("0");
            }
        }
        for (int i = 0; i < nums1.size(); i++) {
            int num1 = Integer.parseInt(nums1.get(i));
            int num2 = Integer.parseInt(nums2.get(i));
            if (num1 == num2) continue;
            if (num1 < num2) return -1;
            return 1;
        }
        return 0;
    }
}
